﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.Reflection;

namespace SF.Base.Core {
	public sealed class ErrorHelper {
		private ErrorHelper() { }
		private readonly static ResourceManager rsManager = new ResourceManager("SF.Base.Core.Resource.Error", Assembly.GetAssembly(typeof(ErrorHelper)));

		public static string GetErrorMsg(string errorCode) {
			string msg = null;
			try {
				if (errorCode.StartsWith("E")) {
					msg = rsManager.GetString(errorCode);
				}
				else if (errorCode.StartsWith("-")) {
					msg = rsManager.GetString(errorCode.Replace("-", "E"));
				}
				else {
					msg = rsManager.GetString("E" + errorCode);
				}
			}
			catch (Exception ex) {
				Logger.Exception(ex);
			}
			if (msg == null) {
				msg = "系统异常";
			}

			Logger.Detail(errorCode, msg);

			return msg;
		}

		public static string GetErrorMsg(int errorCode) {
			return GetErrorMsg(errorCode.ToString());
		}
	}
}
